Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: introduce setWithMemoryUsage to track set memory in AggExec. #22965

Merged
merged 6 commits into from
Mar 3, 2021

Conversation

wshwsh12
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Problem Summary:
Many partial result of distinct aggregate contains a Set, For example

type partialResult4AvgDistinctDecimal struct {
	partialResult4AvgDecimal
	valSet set.StringSet
}

The memory usage can't be tracked.

What is changed and how it works?

Proposal: xxx

What's Changed:
Introduce setWithMemoryUsage in package aggfuncs, to track the memory usage of set.

I will replace all Set to setWithMemoryUsage in the next PR.

How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Side effects

  • Performance regression
    • Consumes more CPU
    • Consumes more MEM

Release note

  • No release note

@wshwsh12 wshwsh12 requested a review from a team as a code owner February 26, 2021 03:24
@wshwsh12 wshwsh12 requested review from qw4990 and removed request for a team February 26, 2021 03:24
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 26, 2021
@wshwsh12 wshwsh12 requested review from ichn-hu and removed request for qw4990 February 26, 2021 03:24
@wshwsh12
Copy link
Contributor Author

Benchmark Result

Benchmark tracks all memory allocation, but doesn't minus GC memory. So in this cases, Map memory use will be 2 times.
Float64
BenchmarkFloat64SetMemoryUsage/MapRows_0-16 18133598 76.9 ns/op 48 B/op 1 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_100-16 76440 14942 ns/op 3199 B/op 19 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_10000-16 795 1570211 ns/op 389611 B/op 257 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_1000000-16 6 170320706 ns/op 49817870 B/op 38266 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_851968-16 12 103182141 ns/op 27388881 B/op 38336 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_851969-16 9 114823948 ns/op 49667440 B/op 38329 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_425984-16 18 60039823 ns/op 13597523 B/op 19086 allocs/op
BenchmarkFloat64SetMemoryUsage/MapRows_425985-16 18 59216265 ns/op 24739645 B/op 19098 allocs/op
When rownum is 1000000, B will be 18, and the estimated memory is (1<<18)(8(1+8+0)+16) = 23068672. In benchmark result, the result is 49817870.

Int64
BenchmarkInt64SetMemoryUsage/MapRows_0-16 16186348 77.6 ns/op 48 B/op 1 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_100-16 109587 11015 ns/op 3198 B/op 19 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_10000-16 1105 1082723 ns/op 389633 B/op 257 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_1000000-16 8 125177175 ns/op 49833701 B/op 38387 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_851968-16 12 86841121 ns/op 27388939 B/op 38356 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_851969-16 12 93875048 ns/op 49674116 B/op 38355 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_425984-16 27 45411134 ns/op 13601213 B/op 19089 allocs/op
BenchmarkInt64SetMemoryUsage/MapRows_425985-16 25 40704813 ns/op 24740725 B/op 19093 allocs/op
When rownum is 1000000, B will be 18, and the estimated memory is (1<<18)(8(1+8+0)+16) = 23068672. In benchmark result, the result is 49833701.

String
BenchmarkStringSetMemoryUsage/MapRows_0-16 17873625 79.9 ns/op 48 B/op 1 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_100-16 90524 13844 ns/op 5424 B/op 10 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_10000-16 769 1915759 ns/op 715097 B/op 10115 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_1000000-16 4 278824461 ns/op 93452812 B/op 1038068 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_851968-16 6 177443102 ns/op 52171016 B/op 890108 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_851969-16 6 169181730 ns/op 92271781 B/op 890059 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_425984-16 13 86480077 ns/op 25957139 B/op 445012 allocs/op
BenchmarkStringSetMemoryUsage/MapRows_425985-16 12 85994027 ns/op 45993578 B/op 444891 allocs/op
When rownum is 1000000, B will be 18, and the estimated memory is (1<<18)(8(1+16+0)+16) = 39845888. In benchmark result, the result is 93452812.

@wshwsh12 wshwsh12 requested a review from XuHuaiyu February 26, 2021 03:26
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 26, 2021
// See the License for the specific language governing permissions and
// limitations under the License.

package aggfuncs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move the package to util/set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. PTAL again

@XuHuaiyu XuHuaiyu added sig/execution SIG execution type/enhancement The issue or PR belongs to an enhancement. labels Mar 2, 2021
@wshwsh12 wshwsh12 requested a review from lzmhhh123 March 3, 2021 02:37
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • ichn-hu
  • lzmhhh123

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 3, 2021
@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Mar 3, 2021

/merge

@ti-chi-bot
Copy link
Member

@wshwsh12: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 10701a5

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 3, 2021
@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Mar 3, 2021

/run-tics-test

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Mar 3, 2021

/run-sqllogic-test
/run-mybatis-test

@ti-chi-bot
Copy link
Member

@wshwsh12: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Mar 3, 2021

/rebuild
/run-integration-copr-test

@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Mar 3, 2021

/run-integration-copr-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants